#include "drop_out.h"


dropout_layer_t::dropout_layer_t( tdsize in_size, float p_activation ):
	layer_t( layer_type::dropout_layer, in_size, in_size ),
	hitmap( in_size.x, in_size.y, in_size.z ),
	p_activation( p_activation )
{

}

void dropout_layer_t::activate( tensor_t<float>& in )
{
	this->in = in;
	for ( int i = 0; i < in.size.x*in.size.y*in.size.z; i++ )
	{
		bool active = (rand() % RAND_MAX) / float( RAND_MAX ) <= p_activation;
		hitmap.data[i] = active;
		out.data[i] = active ? in.data[i] : 0.0f;
	}
}

void dropout_layer_t::fix_weights()
{
		
}

void dropout_layer_t::calc_grads( tensor_t<float>& grad_next_layer )
{
	for ( int i = 0; i < in.size.x*in.size.y*in.size.z; i++ )
	{
			grads_in.data[i] = hitmap.data[i] ? grad_next_layer.data[i] : 0.0f;
	}
}

